package com.oldbook.manage.controller;

import com.oldbook.common.annotation.Log;
import com.oldbook.common.core.controller.BaseController;
import com.oldbook.common.core.domain.AjaxResult;
import com.oldbook.common.core.page.TableDataInfo;
import com.oldbook.common.enums.BusinessType;
import com.oldbook.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.oldbook.manage.domain.TextbookCategory;
import com.oldbook.manage.service.ITextbookCategoryService;


/**
 * 教材分类Controller
 *
 * @author Exiaoke
 * @date 2025-02-17
 */
@RestController
@RequestMapping("/manage/category")
@Api(tags = "教材分类管理")
public class TextbookCategoryController extends BaseController {

    @Autowired
    private ITextbookCategoryService textbookCategoryService;

/**
 * 查询教材分类列表
 */
@PreAuthorize("@ss.hasPermi('manage:category:list')")
@GetMapping("/list")
@ApiOperation("查询教材分类列表")
    public TableDataInfo list(@ApiParam("教材分类对象") TextbookCategory textbookCategory) {
        startPage();
        List<TextbookCategory> list = textbookCategoryService.selectTextbookCategoryList(textbookCategory);
        return getDataTable(list);
    }

    /**
     * 导出教材分类列表
     */
    @PreAuthorize("@ss.hasPermi('manage:category:export')")
    @Log(title = "教材分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出教材分类列表")
    public void export(HttpServletResponse response, @ApiParam("教材分类对象") TextbookCategory textbookCategory) {
        List<TextbookCategory> list = textbookCategoryService.selectTextbookCategoryList(textbookCategory);
        ExcelUtil<TextbookCategory> util = new ExcelUtil<TextbookCategory>(TextbookCategory.class);
        util.exportExcel(response, list, "教材分类数据");
    }

    /**
     * 获取教材分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:category:query')")
    @GetMapping(value = "/{categoryId}")
    @ApiOperation("获取教材分类详细信息")
    public AjaxResult getInfo(@PathVariable("categoryId") @ApiParam("categoryId的值") Long categoryId) {
        return success(textbookCategoryService.selectTextbookCategoryByCategoryId(categoryId));
    }

    /**
     * 新增教材分类
     */
    @PreAuthorize("@ss.hasPermi('manage:category:add')")
    @Log(title = "教材分类", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增教材分类")
    public AjaxResult add(@RequestBody @ApiParam("要添加的教材分类对象") TextbookCategory textbookCategory) {
        return toAjax(textbookCategoryService.insertTextbookCategory(textbookCategory));
    }

    /**
     * 修改教材分类
     */
    @PreAuthorize("@ss.hasPermi('manage:category:edit')")
    @Log(title = "教材分类", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改教材分类")
    public AjaxResult edit(@RequestBody @ApiParam("要修改的教材分类对象") TextbookCategory textbookCategory) {
        return toAjax(textbookCategoryService.updateTextbookCategory(textbookCategory));
    }

    /**
     * 删除教材分类
     */
    @PreAuthorize("@ss.hasPermi('manage:category:remove')")
    @Log(title = "教材分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{categoryIds}")
    @ApiOperation("删除教材分类")
    public AjaxResult remove(@PathVariable @ApiParam("要删除的categoryId数组") Long[] categoryIds) {
        return toAjax(textbookCategoryService.deleteTextbookCategoryByCategoryIds(categoryIds));
    }


}